package com.feifan.web.controller;

import com.feifan.mapper.ContentMapper;
import com.feifan.mapper.UserMapper;
import com.feifan.pojo.UserDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author Donald
 * @create 2019-03-20 0:39
 */
@Controller
public class Test {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ContentMapper contentMapper;

    @RequestMapping("get")
    @ResponseBody
    public Object get() throws SQLException
    {
        contentMapper.readCountAdd(1L);
        contentMapper.likeCountAdd(1,1,"");
        UserDTO userDTO = new UserDTO();
        userDTO.setCreateTime(new Date());
        List<String> st = new ArrayList<String>();
        st.add("ss");
        userDTO.setId(2L);
        userDTO.setRoleList(st);
        //userMapper.insert(userDTO);
        userDTO = userMapper.selectById(userDTO.getId());
        System.out.println(userDTO);
        System.err.println(userMapper.findUserInfoById( 2L ));
        userDTO = userMapper.findAllRolesByUserId(2L);
        System.err.println(userDTO);
        //throw new RuntimeException("niji");
        userMapper.insert(userDTO);
        userMapper.insertRole(userDTO.getId());
        System.out.println(userMapper.findAllRolesByUserId(userDTO.getId()));
        userDTO.setLastLoginTime(new Date());
        userMapper.updateById(userDTO);
        return  userDTO;
    }

}
